<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page session="false"%>
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>Toa Thuốc</title>
<style type="text/css">
.tg {
	border-collapse: collapse;
	border-spacing: 0;
	border-color: #ccc;
}

.tg td {
	font-family: Arial, sans-serif;
	font-size: 14px;
	padding: 10px 5px;
	border-style: solid;
	border-width: 1px;
	overflow: hidden;
	word-break: normal;
	border-color: #ccc;
	color: #333;
	background-color: #fff;
}

.tg th {
	font-family: Arial, sans-serif;
	font-size: 14px;
	font-weight: normal;
	padding: 10px 5px;
	border-style: solid;
	border-width: 1px;
	overflow: hidden;
	word-break: normal;
	border-color: #ccc;
	color: #333;
	background-color: #f0f0f0;
}

.tg .tg-4eph {
	background-color: #f9f9f9
}
</style>
<link href="<c:url value="/resources/css/jquery-ui.min.css" />" rel="stylesheet">
<script src="<c:url value="/resources/js/jquery-1.11.2.min.js" />"></script>
<script src="<c:url value="/resources/js/jquery-ui.min.js" />"></script>
<script src="<c:url value="/resources/js/prescription.js" />"></script>

</head>
<body>
	<h1>Thêm Toa Thuốc</h1>
	<c:if test="${!empty message}">
		<spring:message text="${message}" />
	</c:if>
	<c:if test="${!empty listPatients}">
		<ul id="listPatients" style="display:none">
			<c:forEach items="${listPatients}" var="patient">

				<li value="${patient.id}" data-patientDOB="${patient.dateOfBirth}">${patient.name}</li>

			</c:forEach>
		</ul>
	</c:if>
	<c:url var="aAction" value="/prescription/add"></c:url>
	<form:form action="${aAction}" method="POST" commandName="prescription">
		<table>
			<c:if test="${!empty message}">
				<tr>
					<td colspan="3">${message}</td>
				</tr>
			</c:if>
			<c:if test="${!empty prescription.createDate}">
				<tr>
					<td><form:label path="id">
							<spring:message text="ID" />
						</form:label></td>
					<td><form:input path="id" readonly="true" size="8"
							disabled="true" /> <form:hidden path="id" /></td>
				</tr>
			</c:if>
			<tr>
				<td><form:label path="belongToPatient">
						<spring:message text="Tìm và chọn bệnh nhân " />
					</form:label></td>
				<td>
					<c:choose>
			            <c:when test="${!empty prescription.belongToPatient}">
			                <form:hidden path="belongToPatient" value="${prescription.belongToPatient.id}" id="hiddenPatient"/>
			            </c:when>
			            <c:otherwise>
			                <form:hidden path="belongToPatient" id="hiddenPatient"/>
			            </c:otherwise>
			        </c:choose>
					<input id="txtSearchPatients" />
				</td>
			</tr>
			<tr>
				<fmt:formatDate value="${prescription.createDate}" var="dateCreate" pattern="dd/MM/yyyy" />
				<td><form:label path="createDate">
						<spring:message text="Chọn Ngày Lập Toa " />
					</form:label></td>
				<td><form:input path="createDate" id="txtCreateDate" value="${dateCreate}"/></td>
			</tr>
			<tr>
				<td><form:label path="diagnostic">
						<spring:message text="Chuẩn Đoán" />
					</form:label></td>
				<td>
					<form:input path="diagnostic" />
				</td>
			</tr>
			<tr>
				<td><form:label path="note">
						<spring:message text="Ghi Chú" />
					</form:label></td>
				<td>
					<form:input path="note" />
				</td>
			</tr>
			<tr>
				<td><label>
						<spring:message text="Tiền Khám Bệnh" />
					</label></td>
				<td>
					<input id="idTienKham" name="tien_kham_benh" />
				</td>
			</tr>
			<tr>
				<td colspan="2"><form:label path="prescriptionMedicine">
						<spring:message text="Thêm Toa Thuốc " />
					</form:label></td>
				<td>
			</tr>
			<tr>
				<td>
						<spring:message text="Danh Sách Thuốc " />
				</td>
				<td>
						<spring:message text="Thành Tiền" />
				</td>
			</tr>
			<tr>
				<td>
					<c:if test="${!empty listMedicines}">
						<ul id="listMedicines" style="list-style: none;">
						<c:forEach items="${listMedicines}" var="md">
							<li data-pricevalue="${md.priceValue }" data-numofmedicine="${md.numOfMedicine }" value="${md.id}">
								<input id="${md.id}" type="checkbox" onclick="chooseMedicine(this);" name="inputChooseMedicine"/>${md.medicineName} - ${md.manufactureName}
							</li>
						</c:forEach>
						</ul>
					</c:if>
				</td>
				<td>
					<h1 id="totalMoney"></h1>
			        <form:hidden path="prescriptionMedicine" id="prescriptionMedicine"/>
			        <form:hidden path="cost" id="hiddenCost"/>
				</td>
			</tr>
			<tr>
				<td colspan="2"><c:if
						test="${!empty prescription.createDate}">
						<input id="addPrescription" onclick="addPrescription()" type="submit" value="<spring:message text="Chỉnh Sửa"/>" />
					</c:if> <c:if test="${empty prescription.createDate}">
						<input id="addPrescription" onclick="addPrescription()" type="submit" value="<spring:message text="Thêm Toa Thuốc"/>" />
					</c:if></td>
			</tr>
		</table>
	</form:form>
	<br>
	<c:if test="${!empty listPrescriptions}">
		<h3>Liệt Kê Toa Thuốc</h3>
		<table class="tg">
			<tr>
				<th width="80">Ngày Tháng</th>
				<th width="120">Tên Bệnh Nhân</th>
				<th width="120">Chuẩn Đoán</th>
				<th width="60">Edit</th>
				<th width="60">Delete</th>
			</tr>
			<c:forEach items="${listPrescriptions}" var="pt">
				<tr>
					<td>${pt.createDate}</td>
					<td>${pt.belongToPatient.name}</td>
					<td>${pt.diagnostic}</td>
					<td><a href="<c:url value='/prescription/edit/${pt.id}' />">Edit</a></td>
					<td><a href="<c:url value='/prescription/remove/${pt.id}' />">Delete</a></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>
</body>
</html>